import 'dart:convert';

class ResponseModel<T> {
  final int code;
  final T data;
  final String msg;

  ResponseModel(this.code, this.data, this.msg);

  // /// 初始化列表方式赋值
  // ResponseModel.fromJson(Map<String, dynamic> json)
  //     : code = json['code'],
  //       data = json['data'],
  //       msg = json['msg'] ?? '服务器出现问题，请及时排查';

  /// 工厂函数初始化
  factory ResponseModel.fromJson(Map<String, dynamic> json) {
    return ResponseModel(json['code'], json['data'], json['msg']);
  }

  Map<String, dynamic> toJson() {
    return {'code': code, 'data': json.encode(data), 'msg': msg};
  }
}
